﻿namespace Sidvall.Data.Sqlite
{
    public static class SqlManager
    {
        #region Public Members

        #region GetSqlDeleteQuery

        public static SqlQuery GetSqlDeleteQuery(string tableName, IFilterItem filter, System.Collections.Generic.IEnumerable<global::Sidvall.Data.ISortItem> sortItems,
            int? rowStartIndex, int? rowCount)
        {
            return InternalSqlManager.GetSqlDeleteQuery(tableName, filter, sortItems, rowStartIndex, rowCount);
        }
        public static SqlQuery GetSqlDeleteQuery(string tableName, IFilterItem filter, System.Collections.Generic.IEnumerable<global::Sidvall.Data.ISortItem> sortItems,
            int? rowStartIndex, int? rowCount, RelationItemCollection relations)
        {
            return InternalSqlManager.GetSqlDeleteQuery(tableName, filter, sortItems, rowStartIndex, rowCount, relations);
        }
        public static SqlQuery GetSqlDeleteQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, object item, System.Type itemType)
        {
            return InternalSqlManager.GetSqlDeleteQuery(tableName, fields, item, itemType);
        }

        #endregion
        #region GetSqlInsertQuery

        public static SqlQuery GetSqlInsertQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, object item, System.Type itemType)
        {
            return InternalSqlManager.GetSqlInsertQuery(tableName, fields, item, itemType);
        }
        public static SqlQuery GetSqlInsertQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, System.Collections.Generic.IDictionary<string, object> fieldValues)
        {
            return InternalSqlManager.GetSqlInsertQuery(tableName, fields, fieldValues);
        }

        #endregion
        #region GetSqlSelectQuery

        public static SqlQuery GetSqlSelectQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, IFilterItem filter,
            System.Collections.Generic.IEnumerable<global::Sidvall.Data.ISortItem> sortItems, int? rowStartIndex, int? rowCount)
        {
            return InternalSqlManager.GetSqlSelectQuery(tableName, fields, filter, sortItems, rowStartIndex, rowCount);
        }
        public static SqlQuery GetSqlSelectQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, IFilterItem filter,
            System.Collections.Generic.IEnumerable<global::Sidvall.Data.ISortItem> sortItems, int? rowStartIndex, int? rowCount, RelationItemCollection relations)
        {
            return InternalSqlManager.GetSqlSelectQuery(tableName, fields, filter, sortItems, rowStartIndex, rowCount, relations);
        }

        #endregion
        #region GetSqlSelectCountQuery

        public static SqlQuery GetSqlSelectCountQuery(string tableName, IFilterItem filter)
        {
            return InternalSqlManager.GetSqlSelectCountQuery(tableName, filter);
        }
        public static SqlQuery GetSqlSelectCountQuery(string tableName, IFilterItem filter, RelationItemCollection relations)
        {
            return InternalSqlManager.GetSqlSelectCountQuery(tableName, filter, relations);
        }

        #endregion
        #region GetSqlUpdateQuery

        public static SqlQuery GetSqlUpdateQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, System.Collections.Generic.IDictionary<string, object> fieldValues)
        {
            return InternalSqlManager.GetSqlUpdateQuery(tableName, fields, fieldValues);
        }
        public static SqlQuery GetSqlUpdateQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, System.Collections.Generic.IDictionary<string, object> fieldValues,
            IFilterItem filter)
        {
            return InternalSqlManager.GetSqlUpdateQuery(tableName, fields, fieldValues, filter);
        }
        public static SqlQuery GetSqlUpdateQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, object item, System.Type itemType)
        {
            return InternalSqlManager.GetSqlUpdateQuery(tableName, fields, item, itemType);
        }
        public static SqlQuery GetSqlUpdateQuery(string tableName, System.Collections.Generic.IEnumerable<FieldItem> fields, object item, System.Type itemType, IFilterItem filter)
        {
            return InternalSqlManager.GetSqlUpdateQuery(tableName, fields, item, itemType, filter);
        }

        #endregion

        #endregion
        #region Private Members

        #region InternalSqlManager

        private static System.Lazy<Sidvall.Data.SqlManager> _InternalSqlManager = new System.Lazy<Sidvall.Data.SqlManager>(GetSqlManager);
        private static Sidvall.Data.SqlManager InternalSqlManager
        {
            get
            {
                return _InternalSqlManager.Value;
            }
        }

        #endregion

        #region GetSqlManager

        private static Sidvall.Data.SqlManager GetSqlManager()
        {
            return new Sidvall.Data.SqlManager(new SqlProvider());
        }

        #endregion

        #endregion
    }
}
